/*
 * NullCryptoEngine.cpp
 *
 *  Created on: Apr 11, 2011
 *      Author: Paul Woelfel
 */

#include "crypto/null_crypto_engine.h"
#include "logger.h"
#include <cstdlib>

const std::string CNullCryptoEngine::sIniSectionName("NULL_CRYPTO_ENGINE");


CNullCryptoEngine::CNullCryptoEngine(NAudioFormats::SStreamInfo ioStreamInfo) :
	CCryptoEngine(ioStreamInfo),
	mScale(1.0)
{
	// we have nothing to do

}

CNullCryptoEngine::~CNullCryptoEngine() {
	// we have nothing to do

}

int CNullCryptoEngine::encrypt(double *pData, unsigned int pCount) {
	// don't modify the data, just return the count

	printl(0, __FILE__, "encrypt");
	if (mScale != 1.0) {
		for (unsigned int i = 0; i < pCount; i++, pData++) {
			(*pData) = (*pData) * mScale;
		}
	}

	return pCount;
}

int CNullCryptoEngine::decrypt(double *pData, unsigned int pCount) {
	//don't modify the data, just return the count

	printl(0, __FILE__, "decrypt");
	if (mScale != 1.0) {
		for (unsigned int i = 0; i < pCount; i++, pData++) {
			(*pData) = (*pData) / mScale;
		}
	}
	return 0;
}

int CNullCryptoEngine::changeSettings() {
	printl(0, __FILE__, "changeSettings");
	int ret = CCryptoEngine::changeSettings();


	std::string lString;

	if (getPropertiesReader()->containsKey(sIniSectionName, "SCALE")) {
		if (getPropertiesReader()->getValue(sIniSectionName, "SCALE", lString)) {

			printl(0, __FILE__, "read scale");
			mScale = atof(lString.data());

		}
	}
	return ret;
}
